/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.question;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.question.QuestionService;
import shop.services.front.question.bean.Question;
import shop.services.front.questioncategory.QuestioncategoryService;
import shop.services.front.questioncategory.bean.Questioncategory;

import javax.annotation.Resource;
import java.util.List;

/**   
 * @类名称：QuestionController
 * @创建人：Wzl
 * @创建时间：2018-05-09 下午19:24:51      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/front/question")
public class QuestionController extends FrontBaseController<Question> {
    @Resource
    private QuestionService questionService;
    @Resource
    private QuestioncategoryService questioncategoryService;
    @Override
    public Services<Question> getService() {
        return questionService;
    }

    /**
     * 查询全部问题列表
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/selectQuestionList")
    @ResponseBody
    public JSONResult selectQuestionList(Questioncategory questioncategory){
        List<Questioncategory> categoryList = questioncategoryService.selectList(questioncategory);
        if(categoryList!=null&&categoryList.size()>0){
            for(Questioncategory qc :categoryList){
                Question question=new Question();
                question.setCategoryID(qc.getId());
                List<Question> questionList = questionService.selectList(question);
                qc.setQuestionList(questionList);
            }
        }
        jsonResult = new JSONResult();
        jsonResult.setData(categoryList);
        return jsonResult;
    }
}
